package com.hyq.market.ui.login;

import com.hyq.market.api.AbsServiceUtils;
import com.hyq.market.api.BaseRequest;
import com.hyq.market.api.Constant;
import com.hyq.market.bean.LoginInfo;
import com.hyq.market.utils.HttpConnetionUtil;

import org.xutils.http.RequestParams;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/7/26 0026.
 */

public class ModeLogin extends AbsServiceUtils {
    @Override
    public LoginInfo fromJson(String json) {
        LoginInfo info=gson.fromJson(json,LoginInfo.class);
        return info;
    }

    @Override
    public <T> void getData(T t) {
        super.getData(t);
        BaseRequest request= (BaseRequest) t;
        RequestParams params=new RequestParams(Constant.API_loginUp);
        params.addQueryStringParameter("mobile",request.getUname());
        params.addQueryStringParameter("password",request.getId());
        params.setUseCookie(true);
        params.addHeader("User-Agent","Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36");
        params.addHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
        params.addHeader("Accept","application/json, text/javascript, */*; q=0.01");
       // sendToServer(params,2);


        Map<String, String> params2 = new HashMap<>();
        params2.put("mobile",request.getUname());
        params2.put("password",request.getId());
        sendPost(Constant.API_loginUp,params2);

    }

    public  void sendPost(String url,Map<String, String> params) {
       HttpConnetionUtil.post(url,params,this);
    }
}
